/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.tag;

import com.apt.bean.User;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

/**
 *
 * @author Lambach
 */
public class GetUser {

    public static HashMap<Integer, User> getListUser(String query) {
        HashMap<Integer, User> listUser = new HashMap<Integer, User>();
        PreparedStatement ps = null;
        ResultSet rs = null;

        Connection conn = null;
//        
        try {
            conn = Connect_DB.getConnection();

            if (conn != null) {
                ps = conn.prepareStatement(query);
                rs = ps.executeQuery();
                int key = 1;
                while (rs.next()) {
                    int Account_Id = rs.getInt("Account_Id");
                    String User_Password = rs.getString("User_Password");
                    String User_Name = rs.getString("User_Name");
                    String User_Email = rs.getString("User_Email");
                    byte Account_Status = rs.getByte("Account_Status");
                    String Date_Registed = rs.getString("Date_Registed");
                    String Date_Expired = rs.getString("Date_Expired");
                    String Account_Rol = rs.getString("Account_Role");
                    User user = new User(Account_Id, User_Password, User_Name, User_Email, Account_Status, Date_Registed, Date_Expired, Account_Rol);
                    listUser.put(key, user);
                    key++;
                }

            } else {
                System.out.println("Connect is null");
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            Connect_DB.close(rs, null, ps, conn);
        }
        return listUser;
    }

    public static void connectionClose() {
    }
}
